/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package Project;

import Common.IAttribute;
import Common.IAttributeCollection;
import Common.IUnit;
import Common.IUnitCollection;
import Common.IUnitHolder;

/**
 *
 * @author Администратор
 */
public class Unit implements IUnit {

    private AttributeCollection attributes;
    private IUnitCollection dependencies;
    int uid;
    IUnitHolder unitHolder;

    public Unit(IUnitHolder unitHolder) {
        this.unitHolder = unitHolder;
        this.attributes = new AttributeCollection(this);
        this.dependencies = new UnitCollection(this);

        this.setAttribute("Name").setValue("");
        this.setAttribute("Description").setValue("");
        this.setUID(uid);
    }

    //<editor-fold defaultstate="collapsed" desc="Initialize IUnit">

    public int getUID() {
        return this.uid;
    }

    public void setUID(int uid) {
        this.uid = uid;
    }

    public IUnitHolder getUnitHolder() {
        return this.unitHolder;
    }

    public void setUnitHolder(IUnitHolder unitHolder) {
        this.unitHolder = unitHolder;
    }

    public IAttributeCollection getAttributes() {
        return this.attributes;
    }

    protected IAttribute getAttribute(String name) {
        return this.attributes.getAttribute(name);
    }

    protected IAttribute setAttribute(String name) {
        if (this.attributes.containsKey(name)) {
            return this.attributes.getAttribute(name);
        }
        this.attributes.setAttribute(name, new Attribute(this, name));
        return this.attributes.getAttribute(name);
    }

    public String getUnitType() {
        return this.getClass().getName();
    }

    public String getName() {
        return this.getAttribute("Name").getValue().toString();
    }

    public void setName(String name) {
        this.getAttribute("Name").setValue(name);
    }
    
    public String getDescription() {
        return this.getAttribute("Description").getValue().toString();
    }

    public void setDescription(String description) {
        this.getAttribute("Description").setValue(description);
    }

    //</editor-fold>
}
